import { readable, derived } from 'svelte/store';


export const time = readable(new Date(), function start(set) {
	const interval = setInterval(() => {
		set(new Date());
	}, 1000);

	return function stop() {
		clearInterval(interval);
	};
});

export type NextTick = (val: number) => void;

export const makeTicker$ = (tick: number) => {
	return readable(new Date(), function start(set) {
		const interval = setInterval(() => {
			console.log('tickering=>')
			set(new Date());
		}, tick * 1000);

		return function stop() {
			console.log(`stoping ticker[${tick}]`);
			clearInterval(interval);
		};
	});
};
